﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class RegistrationDal
    {
        DBHepler helper = new DBHepler();

        /// <summary>
        /// 报名信息的添加
        /// </summary>
        /// <param name="reg"></param>
        /// <returns></returns>
        public bool AddRegistration(Model.Registration reg)
        {
            SqlParameter[] parameters = {
                                            new SqlParameter("@proId",reg.proId),
                                            new SqlParameter("@regAccount",reg.regAccount),
                                            new SqlParameter("@regAddress",reg.regAddress),
                                            new SqlParameter("@regBirthday",reg.regBirthday),
                                            new SqlParameter("@regDegree",reg.regDegree),
                                            new SqlParameter("@regIDCard",reg.regIDCard),
                                            new SqlParameter("@regMail",reg.regMail),
                                            new SqlParameter("@regName",reg.regName),
                                            new SqlParameter("@regNative",reg.regNative),
                                            new SqlParameter("@regPhone",reg.regPhone),
                                            new SqlParameter("@regSchool",reg.regSchool),
                                            new SqlParameter("@regSex",reg.regSex),
                                            new SqlParameter("@regZip",reg.regZip)
                                        };
            if (helper.InsertByProc("sp_AddRegisration", parameters) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 获取报名信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetRegistrationAll()
        {
            return helper.GetDataTableByProc("sp_GetAllRegistration");
        }

        /// <summary>
        /// 返回某个报名学员的信息
        /// </summary>
        /// <param name="regId"></param>
        /// <returns></returns>
        public DataTable GetRegistrationById(int regId)
        {
            SqlParameter[] parameters = {
                                            new SqlParameter("@regId",regId)
                                        };
            return helper.GetDataTableByProc("sp_GetRegistrationById",parameters);
        }

        //录取学生
        public bool Luqu(string stuId,string password,string name,int regId)
        {
            SqlParameter[] parameters ={
                                        new SqlParameter("@stuId",stuId),
                                        new SqlParameter("@password",password),
                                        new SqlParameter("@name",name),
                                        new SqlParameter("@regId",regId)
                                      };
            if (helper.InsertByProc("cp_Luqu", parameters) == 3)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
